﻿/*
 * Copyright (c) United Binary LLC.  All rights reserved.
 * 
 * This code is licensed under the MIT License
 * 
 * SEE: http://harnessit.codeplex.com/license
 * 
 */
using System;
using System.Windows.Forms;

namespace UnitedBinary.HarnessIt
{
	public class Program
	{
		[STAThread]
		private static int Main()
		{
			try
			{
#pragma warning disable 0618
				AppDomain.CurrentDomain.AppendPrivatePath( "bin" );
				AppDomain.CurrentDomain.AppendPrivatePath( @"bin\Execution Engines" );
				AppDomain.CurrentDomain.AppendPrivatePath( "AssemblyTemp" );
#pragma warning restore 0618

				Application.EnableVisualStyles();
				Application.SetCompatibleTextRenderingDefault( false );

				//MainForm.Splash = new SplashForm();
				//MainForm.Splash.Show();
				//MainForm.Splash.ForceUpdate();

				MainForm frm = new MainForm();

				Application.Run( frm );

				if ( frm.TestsFailed )
				{
					return 1;
				}
				return 0;
			}
			catch ( Exception e )
			{
				string msg = "An error has occurred during intialization of HarnessIt:\n" + e.Message;
				msg = msg.Replace( "\r\n", "\n" ).Replace( "\n", "\r\n" );

				if ( SystemInformation.UserInteractive )
				{
					DetailedErrorForm.Show( msg, "Full exception details:\r\n\r\n" + e );
				}
				else
				{
					EmergencyLog.WriteLine( "Exception error.", msg );
				}
				return -1;
			}
		}
	}
}
